﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace tiDE
{
    public partial class OutputWindow : DockContent
    {
        string OldValue;

        public void Write(string Value)
        {
            Console.Write(Value);
            OutputText += Value;
        }

        public void WriteLine(string Value)
        {
            Console.WriteLine(Value);
            OutputText += Value + Environment.NewLine;
        }

        public void Clear()
        {
            OutputText = "";
        }

        public string OutputText
        {
            get
            {
                return textBox1.Text;
            }
            set
            {
                OldValue = value;
                OutputTextAsync(value);
            }
        }

        delegate void OutputTextAsyncDelegate(string Text);
        void OutputTextAsync(string Text)
        {
            if (this.InvokeRequired)
            {
                OutputTextAsyncDelegate invokeDelegate = new OutputTextAsyncDelegate(OutputTextAsync);
                this.Invoke(invokeDelegate, new object[] { Text });
            }
            else
            {
                textBox1.Text = Text;
            }
        }

        public OutputWindow()
        {
            InitializeComponent();
            OldValue = textBox1.Text;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox1.Text = OldValue;
        }
    }
}
